package com.wgcloud.util.response;

import com.wgcloud.entity.Result;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

/**
 * 工具类，用于构建响应实体
 */
public class ResponseUtil {

    // 返回成功的响应
    public static <T> ResponseEntity<Result<T>> success(T data) {
        Result<T> response = new Result<>(HttpStatus.OK.value(), "Success", data);
        return new ResponseEntity<>(response, HttpStatus.OK);
    }

    // 返回失败的响应
    public static <T> ResponseEntity<Result<T>> error(int code, String message) {
        Result<T> response = new Result<>(code, message, null);
        return new ResponseEntity<>(response, HttpStatus.valueOf(code));
    }

    // 返回自定义状态码的响应
    public static <T> ResponseEntity<Result<T>> customResponse(int code, String message, T data) {
        Result<T> response = new Result<>(code, message, data);
        return new ResponseEntity<>(response, HttpStatus.valueOf(code));
    }
}